<div class="doc-item" id="doc-662"><h2 class="doc-item-name">choose<span class="namespace">(clojure.contrib.probabilities.finite-distributions)</span></h2><ul class="var-arglists"><li>(<span class="var-name">choose</span> &amp; choices)</li></ul><div class="var-docstring"><p>Construct a distribution from an explicit list of probabilities
   and values. They are given in the form of a vector of probability-value
   pairs. In the last pair, the probability can be given by the keyword
   :else, which stands for 1 minus the total of the other probabilities.</p></div><div class="var-source"><pre>; clojure/contrib/probabilities/finite_distributions.clj:94
(defn choose
  [&amp; choices]
  (letfn [(add-choice [dist [p v]]
	    (cond (nil? p) dist
		  (= p :else)
		        (let [total-p (reduce + (vals dist))]
			  (assoc dist v (- 1 total-p)))
		  :else (assoc dist v p)))]
    (reduce add-choice {} (partition 2 choices))))</pre></div><div class="license"><p>Copyright (c) Rich Hickey. All rights reserved.</p><p>The use and distribution terms for this software are covered by the <a href="http://opensource.org/licenses/eclipse-1.0.php">Eclipse Public License 1.0</a>, which can be found in the file
          epl-v10.html at the root of this distribution. By using this software
          in any fashion, you are agreeing to be bound by the terms of this
          license. You must not remove this notice, or any other, from this
          software.</p></div></div>